package com.pkk.penguin.frame.know.java.jvm.classload;

import java.net.URL;
import sun.misc.Launcher;
import sun.util.cldr.CLDRLocaleDataMetaInfo;

/**
 * @description: 类加载器的加载路径
 * @author: peikunkun
 * @create: 2020-02-20 12:20
 **/
public class ClassLoader2 {

  public static void main(String[] args) {
    System.out.println("启动类/引导类加载器的加载路径:");
    final URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
    //或者下面的都可以查看出启动类加载器的加载路径
    final String urLs1 = System.getProperty("sun.boot.class.path");
    for (URL urL : urLs) {
      System.out.println(urL);
    }

    System.out.println("扩展类加载器:");
    final String extPath = System.getProperty("java.ext.dirs");
    for (String s : extPath.split(";")) {
      System.out.println(s);
    }

    System.out.println("系统类加载器:");
    final String sys = System.getProperty("java.class.path");
    for (String sy : sys.split(";")) {
      System.out.println(sy);
    }

    System.out.println("验证阶段1（同属于扩展类加载器与系统类加载器管辖）应该属于那个加载器呢?【扩展类】");
    final ClassLoader classLoader = CLDRLocaleDataMetaInfo.class.getClassLoader();
    System.out.println(classLoader);
    System.out.println("验证阶段2（同属于启动类加载器与系统类加载器管辖）应该属于那个加载器呢?【启动类】");
    final ClassLoader classLoader1 = String.class.getClassLoader();
    System.out.println(classLoader1);
  }


}
